package com.gh.controller.api;

import com.gh.model.hosp.Hospital;
import com.gh.model.hosp.Schedule;
import com.gh.result.Result;
import com.gh.service.HospitalService;
import com.gh.service.HospitalSetService;
import com.gh.service.ScheduleService;
import com.gh.vo.hosp.DepartmentVo;
import com.gh.vo.hosp.HospitalQueryVo;
import com.gh.vo.hosp.ScheduleOrderVo;
import com.gh.vo.order.SignInfoVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author Eric
 * @Date 2021/6/14 21:15
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospitalApiController {
    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private ScheduleService scheduleService;
    @Autowired
    private HospitalSetService hospitalSetService;
    /**
     * 查询医院列表
     */
    @GetMapping("findHospList/{page}/{limit}")
    public Result findHospList(@PathVariable Integer page,
                               @PathVariable Integer limit,
                               HospitalQueryVo hospitalQueryVo){
        Page<Hospital> pages = hospitalService.selectHospPage(page, limit, hospitalQueryVo);
        return Result.ok(pages);
    }
    /**
     * 根据医院名称查询
     */
    @GetMapping("findByHosName/{hosname}")
    public Result findByHosName(@PathVariable String hosname){
        List<Hospital> hospital = hospitalService.findByHosName(hosname);
        return Result.ok(hospital);
    }
    /**
     * 根据医院编号获取科室列表
     */
    @ApiOperation(value = "根据医院编号获取科室")
    @GetMapping("department/{hoscode}")
    public Result getDepartmentByHoscode(@PathVariable String hoscode){
        List<DepartmentVo> list = hospitalService.findDeptList(hoscode);
        return Result.ok(list);
    }
    /**
     * 根据医院编号获取医院预约挂号详情
     */
    @ApiOperation(value = "根据医院编号获取医院预约挂号详情")
    @GetMapping("findHospitalDetail/{hoscode}")
    public Result findHospitalDetail(@PathVariable String hoscode){
        Map<String,Object> map=hospitalService.findHospitalDetail(hoscode);
        return Result.ok(map);
    }
    /**
     * 获取可预约排班信息
     */
    @GetMapping("auth/getBookingRuleSchedule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingRuleSchedule(@PathVariable Integer page,
                                         @PathVariable Integer limit,
                                         @PathVariable String hoscode,
                                         @PathVariable String depcode){
        return Result.ok(scheduleService.getBookingRuleSchedule(page,limit,hoscode,depcode));
    }


    /**
     * 获取排班具体数据
     */
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(@PathVariable String hoscode,
                                   @PathVariable String depcode,
                                   @PathVariable String workDate){
        return Result.ok(scheduleService.getScheduleList(hoscode,depcode,workDate));
    }

    /**
     * 根据排班id获取排班数据
     * @param scheduleId
     * @return
     */
    @ApiOperation(value = "根据排班id获取排班数据")
    @GetMapping("getSchedule/{scheduleId}")
    public Result getSchedule(@PathVariable String scheduleId){
        Schedule schedule = scheduleService.getById(scheduleId);
        return Result.ok(schedule);
    }
    /**
     * 根据排班id获取预约下单数据
     */
    @GetMapping("/inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@PathVariable String scheduleId){
        return scheduleService.getScheduleOrderVo(scheduleId);
    }
    /**
     * 获取医院签名信息
     */
    @GetMapping("inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(@PathVariable String hoscode){
        return hospitalSetService.getSignInfoVo(hoscode);
    }
}
